<template>
  <!-- 管理端 页面配置 -->
  <div class="app-container jklis">
    <div class="zdy-main">
      <el-tabs type="border-card" v-model="actived" @tab-click="tabChange" v-loading="loading">
        <el-form ref="queryForm" :inline="true" class="search-form-new" label-width="68px">
          <el-form-item class="btns">
            <el-button icon="el-icon-plus" type="primary" @click="addACount">新增</el-button>
          </el-form-item>
        </el-form>
        <el-tab-pane :label="tab.name" :name="tab.value" v-for="tab in statusList" :key="tab.value">
          <div class="table_box">
            <el-table :data="tableData.records" @cell-dblclick="handleUpdate" 
            style="width: 100%">
              <el-table-column label="排序" prop="sort" width="120"/>
              <el-table-column label="标题" prop="name" />
              <el-table-column label="简介" prop="remark" v-if="actived==2"/>
              <el-table-column label="视频地址"  prop="url" v-if="actived==2||actived==3">
                <template slot-scope="scope">
                  <span>{{ scope.row.url }}</span>
                </template>
              </el-table-column>
              <el-table-column label="图片"  prop="imgUrl" >
                <template slot-scope="scope">
                  <el-image :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]" alt="" style="height: 32px;" />
                </template>
              </el-table-column>
              <el-table-column label="是否启用" width="150px" prop="isShow" v-if="actived == '2'">
                <template #default="scope">
                  <el-button type="success" size="mini" v-if="scope.row.isShow == 1" disabled plain>启用</el-button>
                  <el-button type="danger" size="mini" v-if="scope.row.isShow == 2" disabled plain>未启用</el-button>
                </template>
              </el-table-column>
              <el-table-column label="操作" >
                <template slot-scope="scope">
                  <el-button type="edit"  size="mini" @click.stop="handleUpdate(scope.row)">编辑</el-button>
                  <el-button type="del" style="color: red" size="mini" @click="delItem(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 一下是弹出框 -->
    <addDialog ref="addDialog"></addDialog>
    <!-- <detailDialog ref="detailDialog"></detailDialog> -->
  </div>
</template>

<script>
import addDialog from "./add.vue";
import resourcesManage from '@/api/PCWebImages/resourcesManage'
export default {
  name: "financial",
  components: { addDialog },
  data() {
    return {
      tableData: {
        records: [],
        total: 0
      },
      upLoadUrl: "",
      loading: false,
      statusList: [
        // {
        //   name: "ERP首页轮播",
        //   value: '1'
        // },
        {
          name: "视频介绍",
          value: '2'
        },
        // {
        //   name: "官网首页视频",
        //   value: '3'
        // },
        // {
        //   name: "指导文章",
        //   value: '3'
        // },
        // {
        //   name: "教学视频",
        //   value: '4'
        // },
      ],
      actived: '2',
    };
  },
  created() {
    this.upLoadUrl =
      process.env.VUE_APP_BASE_API + "/account/finance/importData";
    this.getList();
    // this.getTypeList();
  },
  activated() {
    this.getList();
  },
  methods: {
    // 获取列表
    getList() {
      this.tableData.records = [];
      this.loading = true;
      let obj = {
        systemType: this.actived
      }
      resourcesManage
        .getList(obj)
        .then(response => {
          console.log("%c Line:111 🥑 response", "color:#42b983", response);
          this.$nextTick(() => {
            this.loading = false;
            this.tableData.records = JSON.parse(JSON.stringify(response.rows));
            // this.tableData.total = response.total;
          });
        })
        .catch(err => {
          this.loading = false;
        });
    },
    // 搜索
    search() {
      this.getList();
    },
    // tabs切换时触发
    tabChange() {
      this.search();
    },
    // 新增
    addACount() {
      this.$refs.addDialog.open(this.actived,"add");
    },
    // 双击编辑
    handleUpdate(row) {
      // 查看详情
      this.$refs.addDialog.open(this.actived,"edit", row);
    },
    // 删除记录
    delItem(row) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          resourcesManage.del(row.id).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.getList()
          });
        })
        .catch(() => { });
    },

  }
};
</script>
<style lang="scss" scoped></style>
